//
//  CoinRecordView.swift
//  Exchange
//
//  Created by 孟祥群 on 2018/5/22.
//  Copyright © 2018年 common. All rights reserved.
//

import UIKit

class CoinRecordView: BaseView, UITableViewDelegate, UITableViewDataSource {
    lazy var tableView:UITableView = UITableView(frame: CGRect.zero, style: UITableViewStyle.grouped)
    lazy var headView: UIView = {
        let view = UIView()
        view.frame = CGRect(x: 0, y: 0, width: kSCREEN_WIDTH, height: 155)
        view.backgroundColor = kTitleColor
        return view
    }()
    lazy var useLabel: UILabel = {
        let label = BaseLabel(style: .twiceStyle)
        label.font = UIFont.systemFont(ofSize: 11)
        label.text = "\(kText("可用"))  0.14344544BTC"
        return label
    }()
    
    lazy var nameLabel: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = UIColor(hexStr: "#e7ebf4")
        label.text = "0 BTC"
        label.changeLabelTextStyle(title: "0", color: label.textColor, font: UIFont.systemFont(ofSize: 36))
        return label
    }()
    lazy var moneyLabel:UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.textColor = UIColor(hexStr: "#757b86")
        label.text = "≈ 3456.45 CNY"
        return label
    }()
    lazy var footView: UIView = {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: kSCREEN_WIDTH, height: 100))
        return view
    }()
    
    override init(dataSource: BaseViewModel?) {
        super.init(dataSource: dataSource)
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func setUpUI() {
        super.setUpUI()
        
        self.addSubview(tableView)
        tableView.separatorStyle = UITableViewCellSeparatorStyle.none
        tableView.delegate = self
        tableView.dataSource = self
        tableView.backgroundColor = UIColor.clear
        tableView.snp.makeConstraints { (make) in
            make.left.right.bottom.top.equalToSuperview()
        }
        tableView.tableHeaderView = headView
        
        headView.addSubview(nameLabel)
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(27)
            make.centerX.equalToSuperview()
        }
        
        headView.addSubview(moneyLabel)
        moneyLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(73)
            make.centerX.equalToSuperview()
        }
        
        for i in 0..<2 {
            let availLabel = UILabel()
            availLabel.font = UIFont.systemFont(ofSize: 11)
            availLabel.textColor = kContrnColor
            availLabel.text = kText("可用")
            headView.addSubview(availLabel)
            availLabel.snp.makeConstraints { (make) in
                make.top.equalToSuperview().offset(107)
                make.left.equalToSuperview().offset(i==0 ? 50.00 : kSCREEN_WIDTH/2+50)
            }
            
            let numberLabel = UILabel()
            numberLabel.font = UIFont.systemFont(ofSize: 13)
            numberLabel.textColor =  kContrnColor
            headView.addSubview(numberLabel)
            numberLabel.snp.makeConstraints { (make) in
                make.left.equalTo(availLabel)
                make.top.equalTo(availLabel.snp.bottom).offset(10)
            }
        }
        
    }
    
    //MARK tableViewDelegate
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        return 1
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:BaseTableViewCell = BaseCellFactory .createTableViewCellWithModel(model: BaseModel(), tableView: tableView, style: .BaseStyleCell)
        cell.selectionStyle = .none
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        
        return 40
    }
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: kSCREEN_WIDTH, height: 40))
        view.backgroundColor = UIColor.clear
        
        let recordLabel = UILabel()
        recordLabel.font = UIFont.systemFont(ofSize: 12)
        recordLabel.textColor  = UIColor(hexStr: "#757b86")
        recordLabel.text = kText("最新的3条记录")
        view.addSubview(recordLabel)
        recordLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(16)
        }
        
        let allBtn = UIButton()
        allBtn.setTitle(kText("全部"), for: UIControlState.normal)
        allBtn.setTitleColor(UIColor(hexStr: "#757b86"), for: UIControlState.normal)
        allBtn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
        view.addSubview(allBtn)
        allBtn.snp.makeConstraints { (make) in
            make.right.equalToSuperview().offset(-16)
            make.centerY.equalToSuperview()
        }
        
        
        return view
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: false)
    }
    
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
